package com.thingsgrid.device.controller;

import com.thingsgrid.common.constant.ResponseCodeConstant;
import com.thingsgrid.device.service.DeviceMaintenanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.*;


/**
 * 功能说明：设备维护controller
 *
 * @author 李龙飞
 * @since 2019/9/4 15:21
 */

@RestController
@AllArgsConstructor
@RequestMapping("device_maintenance")
@Api("设备维护")
public class DeviceMaintenanceController {

	private DeviceMaintenanceService deviceMaintenanceService;

	/**
	 *说明：查询设备列表
	 *@author lilongfei
	 *@since 2019/9/4 15:26
	 */
	@RequestMapping("/getDeviceList")
	@ApiOperation("查询设备列表")
	public R getDeviceList(@RequestParam("productType")String productType,
                           @RequestParam("productId")String productId, @RequestParam("deviceId")String deviceId,
                           @RequestParam("currentPage")Integer currentPage, @RequestParam("pageSize")Integer pageSize){
		return R.data(deviceMaintenanceService.getDeviceList(productType, productId, deviceId, currentPage, pageSize));
	}


	/**
	 *说明：操作设备
	 *@author lilongfei
	 *@since 2019/9/5 15:33
	 */
	@PostMapping("/updateDevice")
	@ApiOperation("操作设备")
	public R updateDevice(@RequestParam("deviceId")String deviceId, @RequestParam("control")String control, @RequestParam("userId")String userId, @RequestParam("productId") String productId){
		Integer result = deviceMaintenanceService.updateDevice(deviceId, control,userId,productId);
		if(result==0){
			return R.success(ResponseCodeConstant.RESPONSE_SUCCESS.getValue());
		}else {
			return R.fail(ResponseCodeConstant.DATAACCESS_ERROR.getValue());
		}
	}

	/**
	 *说明：查询维护记录
	 *@author lilongfei
	 *@since 2019/9/5 20:27
	 */
	@GetMapping("/getDeviceRecordList")
	@ApiOperation("查询维护记录")
	public R getDeviceRecordList(@RequestParam("productType")String productType,
                                 @RequestParam("productId")String productId, @RequestParam("deviceId")String deviceId,
                                 @RequestParam("currentPage")Integer currentPage, @RequestParam("pageSize")Integer pageSize){
		return R.data(deviceMaintenanceService.getDeviceRecordList(productType, productId, deviceId, currentPage, pageSize));
	}

	/**
	 *说明：获取产品类型列表
	 *@author lilongfei
	 *@since 2019/9/6 14:50
	 */
	@GetMapping("/getProductTypeList")
	@ApiOperation("获取产品类型列表")
	public R getProductTypeList(){
		return R.data(deviceMaintenanceService.getProductTypeList());
	}

	/**
	 *说明：根据产品类型查询产品名称
	 *@author lilongfei
	 *@since 2019/9/6 16:11
	 */
	@GetMapping("/getProductList")
	@ApiOperation("根据产品类型查询产品名称")
	public R getProductList(@RequestParam("productType")String productType){
		return R.data(deviceMaintenanceService.getProductList(productType));
	}

	/**
	 *说明：根据产品id查询设备列表
	 *@author lilongfei
	 *@since 2019/9/6 16:34
	 */
	@GetMapping("/getDeviceListByProductId")
	@ApiOperation("根据产品id查询设备列表")
	public R getDeviceListByProductId(@RequestParam("productId")String productId){
		return R.data(deviceMaintenanceService.getDeviceList(productId));
	}

}
